package io.chenglicun.modules.data.param;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.chenglicun.common.utils.DateUtils;
import io.chenglicun.modules.data.entity.statistics.DataDayStatisticsEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.Date;

@Data
@ApiModel(value = "日时间统计数据")
public class DataDayStatisticsParam {
    @ApiModelProperty(value = "农村人居 ruralSettlements 文明城市 civilizedCity")
    private String type;

    @ApiModelProperty(value = "月-0 年-1")
    @Max(value = 1)
    @Min(value = 0)
    private Integer time;

    public Wrapper<DataDayStatisticsEntity> buildQueryWrapper() {
        LambdaQueryWrapper<DataDayStatisticsEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(type),DataDayStatisticsEntity::getType,type);
        if (time == 0){
            queryWrapper.between(DataDayStatisticsEntity::getDayData,DateUtils.getFirstDayOfMonth(),new Date());
        }else {
            queryWrapper.between(DataDayStatisticsEntity::getDayData,DateUtils.getFirstDayOfYear(),new Date());
        }
        queryWrapper.orderByDesc(DataDayStatisticsEntity::getDayTime);
        return queryWrapper;
    }
}
